/*
 * @Author: song
 * @Description:配置面板
 * @Date: 2024年05月03日 星期五 22:05:11
 * @Modify:
 */

using System.Collections.Generic;
using SCore.Editor.WindowDraw;
using UnityEditor;
using UnityEngine;

namespace Function.SkillEditor.Editor
{
    public class SkillConfigSubWindow : IESubWindow
    {
        private SkillConfigPageView _itemView;

        public SkillConfigSubWindow(EditorWindow window) : base(window)
        {
        }

        public override void OnGUI()
        {
            GUILayout.Label("技能配置", EditorStyles.boldLabel);
            base.OnGUI();
            if (GUILayout.Button("保存"))
            {
                SkillEditorConfig.Instance.SaveBy(SkillEditorWindow._config);
                foreach (var itemData in _itemView._pageMap)
                {
                    if (itemData._skillRunLine != null)
                    {
                        SkillEditorConfig.Instance.SaveSkillRunLine(itemData._skillRunLine);
                    }
                }
            }
        }

        protected override List<ICommonView> BindView()
        {
            var resultViews = new List<ICommonView>();
            var bindViews = SkillEditorConfig.Instance.GetWindowConfig(SkillWindowType.Config);
            foreach (var bindView in bindViews._eCommonViews)
            {
                resultViews.Add(bindView);
            }

            _itemView = bindViews._eCommonViews[0] as SkillConfigPageView;
            return resultViews;
        }

        protected override bool MouseDown(Event evt)
        {
            if (evt.button == 0)
            {
                GUI.FocusControl(null);
                GetWindow<SkillEditorWindow>().Repaint();
                evt.Use();
                return true;
            }

            return false;
        }
    }
}